<?php
session_start();
if (!isset($_SESSION['cart']))
{
$_SESSION['cart'] = array();
$_SESSION["quantity"]=array();
$_SESSION["fullpath"]=array();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Softwarez4_IITU</title>
        <link rel=stylesheet type="text/css" href="mystyle.css">
    </head>

        <!--
        <frameset cols="10%,80%,10%">
        <frame src="categories.php" name="left" scrolling="auto"/>
        <frame src="middle.php" name="middle" scrolling="auto"/>
        <frame src="cart.php" name="right" scrolling="auto"/>
        </frameset>
        -->
`   <body>
        
    <h1 align="center">  <font size="7" color="Blue" face="Calibri"> SOFTWARE-MART</font>           </h1>
    <br>
   
    <br>


   <table border="0" width="100%" cellpadding="10"  >
    <tr>

    <td width="20%" valign="top">
        <?php include("categories.php");?>
    </td>

    <td width="70%" valign="top">

        <?php
        //THIS IS OUR MAIN HANDLER WHICH WILL HANDLE ALL KINDS OF EVENTS

            if (isset($_POST['submit']) and $_POST['submit'] == 'Submit')
                {
                // End Shopping session
                 include ("end.php");
                 session_destroy();
                }

            else if (isset($_POST['action']) and $_POST['action'] == 'Checkout')
                {
                // Proceed to Checkout
                    include ("checkout.php");
                }
            else if (isset($_POST['action']) and $_POST['action'] == 'Empty Cart')
                {
                // Empty the cart array
                    $_SESSION["cart"] = array();
                    $_SESSION["quantity"] = array();
                    $_SESSION["fullpath"]=array();
                }
             else if (isset($_POST['action']) and $_POST['action'] == 'Add to Cart')
                {
                    // Add item to the end of the $_SESSION['cart'] array
                    $flag=0;
                    $k=0;
                    foreach ($_SESSION["cart"] as $name)
                    {

                       if ($name==$_POST["id"])
                            {
                                $flag=1;
                                break;
                            }
                       $k+=1;
                    }
                    echo "<font size=\"7\" color=\"Orange\" face=\"Calibri\">One product added to the cart</font>";
                    if ($flag==0){
                    $_SESSION["quantity"][]=$_POST["quantity"];
                    $_SESSION["cart"][] = ($_POST["id"]+0);
                    $_SESSION["fullpath"][]=$_GET["path"];
                    }
                    else
                    {
                        $_SESSION["quantity"][$k]+=$_POST["quantity"];
                    }

                }
             else if(isset($_GET["su"]))
                {
                    include("products.php");
                }
             else if(isset($_GET["view"])){
                    include("viewcart.php");
                    if(count($_SESSION["cart"])==0){
                        echo "<font size=\"5\" color=\"fuschia\" face=\"Calibri\">Cart is Empty</font>";
                    }
                }
             else if(isset($_GET["foo"])){
                        include("middle.php");
                }



             else if (isset($_POST['action2']))
		 {

		  $conn=mysql_connect("localhost","root");
		  mysql_select_db("ShoppingCart",$conn);
		  $result=mysql_query("SELECT * FROM products WHERE name LIKE \"%".$_POST["search"]."%\" ",$conn);
		  while($row=mysql_fetch_array($result))
		      {
		      echo "<img src=\"images/".$row['name'].".jpg\" width=\"70\" height=\"50\">";
		      echo "</br>";
		      echo "<font size=\"5\" color=\"Gray\" face=\"Calibri\">".$row[name]."</font>";
		      echo "</br>";
		      echo "<font size=\"4\" color=\"Gray\" face=\"Trebuchet MS\">".$row[shortdescription]."</font>";
		      echo "</br>";
		      echo "Rs.".$row[price];
		      echo "</br>";
                echo " <a href=\"index.php?su=".$row["name"]."\">"."View More"."</a>";
                echo "</br>";
                echo "</br>";
                echo "</br>";
                echo "</br>";
		}
		}


                else if(isset($_GET["drop"])){
                  $k=0;

                    $cart=array();
                    $quantity=array();
                    $i=0;

                 foreach ($_SESSION["cart"] as $id)
                    {
                       if ($id!=$_GET["drop"])
                            {
                               $cart[]= $id;
                               $quantity[]=$_SESSION["quantity"][$i];
                               $i+=1;
                            }
                    }
                    $_SESSION["cart"]=$cart;
                    $_SESSION["quantity"]=$quantity;
                    include("viewcart.php");

             }



             else{
                        include("home.php");
                }

        ?>

    </td>



    <td  width="10%" valign="top">
        <a href="index.php"><font color="gold">HOME</font></a>

        
        <p><font color="red">Your shopping cart contains </font>
        <?php
            echo "<font color=\"red\">".count($_SESSION['cart'])."</font> ";
            echo "<font color=\"red\"> items </font> "; ?>
         </p>
        </br>
        </br>
        </br>
        </br>
        </br>
        <p><a href="index.php?view=1"><button >View Cart</button></a></p>
        <a href="index.php?view=1"><img src="images/cart.jpg" height="50" width="70"></a></p>
        <br>
        <br>
        <br>
        <br>
        <iframe width="180" height="215" src="scroller_newstic.html" SCROLLING="no" FRAMEBORDER="0" border=0 allowTransparency="true"></iframe>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <script src="scmenujs.js" type="text/javascript"></script><noscript><OBJECT id="scmenuobj" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH=190 HEIGHT=320> <PARAM NAME=movie VALUE="scmenu.swf"> <PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=high> <PARAM NAME=wmode VALUE=opaque> <param name="scale" value="noscale" /> <PARAM NAME=bgcolor VALUE=#000000> <EMBED src="scmenu.swf" menu=false quality=high scale="noscale" wmode=opaque bgcolor=#000000  WIDTH=190 HEIGHT=320 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT></noscript>

    </td>

    </tr>
    </table>



    </body>

    <div align="center">
    <img src="images/paypal.gif" width="70" height="30">
    </div>
</html>
